﻿using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace msBsc.WebUi
{
    public partial class mfIndex : msBsc.Cls.mbPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

    //     #region 数据发送
    //protected void send()
    //{
    //            string sendurl="http://api.sms.cn/mt/";
    //            string mobile = "15808054185";  ////发送号码
    //            string strContent = "您好，您的验证码是111【地接客】";
    //            StringBuilder sbTemp = new StringBuilder();
    //            string uid="dlz65360519";
    //            string pwd="yzz23567828";
    //            string Pass = FormsAuthentication.HashPasswordForStoringInConfigFile(pwd+uid, "MD5"); //密码进行MD5加密
    //            //POST 传值
    //            sbTemp.Append("uid="+uid+"&pwd=" + Pass + "&mobile=" + mobile + "&content=" + strContent);
    //            byte[] bTemp = System.Text.Encoding.GetEncoding("GBK").GetBytes(sbTemp.ToString());
    //            String postReturn = doPostRequest(sendurl, bTemp);
    //            Alert(postReturn);
    //           // Response.Write("Post response is: " + postReturn);  //测试返回结果
    //}
    ////POST方式发送得结果
    //private static String doPostRequest(string url, byte[] bData)
    //{
    //    System.Net.HttpWebRequest hwRequest;
    //    System.Net.HttpWebResponse hwResponse;

    //    string strResult = string.Empty;
    //    try
    //    {
    //        hwRequest = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(url);
    //        hwRequest.Timeout = 5000;
    //        hwRequest.Method = "POST";
    //        hwRequest.ContentType = "application/x-www-form-urlencoded";
    //        hwRequest.ContentLength = bData.Length;

    //        System.IO.Stream smWrite = hwRequest.GetRequestStream();
    //        smWrite.Write(bData, 0, bData.Length);
    //        smWrite.Close();
    //    }
    //    catch (System.Exception err)
    //    {
    //        WriteErrLog(err.ToString());
    //        return strResult;
    //    }

    //    //get response
    //    try
    //    {
    //        hwResponse = (HttpWebResponse)hwRequest.GetResponse();
    //        StreamReader srReader = new StreamReader(hwResponse.GetResponseStream(), Encoding.ASCII);
    //        strResult = srReader.ReadToEnd();
    //        srReader.Close();
    //        hwResponse.Close();
    //    }
    //    catch (System.Exception err)
    //    {
    //        WriteErrLog(err.ToString());
    //    }
    //    return strResult;
    //}
    //private static void WriteErrLog(string strErr)
    //{
    //    Console.WriteLine(strErr);
    //    System.Diagnostics.Trace.WriteLine(strErr);
    //}
    //#endregion

        public override void DoAction()
        {
            base.DoAction();
            if (this.strAction == "GetButiqueInfo")
            {
                GetButiqueInfo();
                //send();
            }
        }

        //获取推荐产品信息
        private void GetButiqueInfo()
        {
            //车辆
            DataSet vds;

            using (msBsc.AppLogic.DataAlc.CBizVehicleInfo objCBizVehicleInfo = new AppLogic.DataAlc.CBizVehicleInfo())
            {
                vds = objCBizVehicleInfo.DataObj.QueryBySQL(@"SELECT TOP 3 
A.VEHICLE_INFO_ID
,A.VEHICLE_DEFAULT_PIC
,A.VEHICLE_PRICE_DAY
,A.VEHICLE_NAME
FROM DJK_VEHICLE_INFO A 
WHERE (A.VEHICLE_RMK IS NULL 
OR A.VEHICLE_RMK<>'T') 
AND LEN(A.VEHICLE_NAME)<=5 
AND A.VEHICLE_PRICE_DAY<1000 
AND A.VEHICLE_STATUS=2
ORDER BY A.VEHICLE_PUBLISH_TIME DESC");
            }
            var strJson = msBsc.AppLogic.Cfg.HttpTools.GetJsonByTable(vds.Tables[0], "", "", 1, 200, "");
            this.ExecJScript(@"var _html = $('#butique_vehicle_list').html();
                            laytpl(_html).render(" + strJson + @", function (render) {
                                $('#butique-vehicle').append(render);
                            })");


            //景区
            DataSet sds;
            using (msBsc.AppLogic.DataAlc.CBizPushScenic objCBizPushScenic = new AppLogic.DataAlc.CBizPushScenic())
            {
                sds = objCBizPushScenic.DataObj.QueryBySQL(@"SELECT TOP 3 
            A.SCENIC_ID
            ,A.SCENIC_NAME
            ,A.SCENIC_DEFAULT_PIC 
            FROM DJK_PUSH_SCENIC A 
            WHERE LEN(A.SCENIC_NAME)<=5 
            ORDER BY A.SCENIC_IS_SPECIE DESC,A.SCENIC_UPLOAD_TIME DESC");
            }

            strJson = msBsc.AppLogic.Cfg.HttpTools.GetJsonByTable(sds.Tables[0], "", "", 1, 200, "");
            this.ExecJScript(@"var _html = $('#butique_scenic_list').html();
                            laytpl(_html).render(" + strJson + @", function (render) {
                                $('#butique-scenic').append(render);
                            })");

            //美食
            DataSet nds;
            using (msBsc.AppLogic.DataAlc.CBizPushNiceFood objCBizPushNiceFood = new AppLogic.DataAlc.CBizPushNiceFood())
            {
                nds = objCBizPushNiceFood.DataObj.QueryBySQL(@"SELECT TOP 3 
            A.NICEFOOD_ID
            ,A.NICEFOOD_NAME
            ,A.NICEFOOD_DEFAULT_PIC 
            FROM DJK_PUSH_NICEFOOD A 
            WHERE LEN(A.NICEFOOD_NAME)<=5 
            ORDER BY A.NICEFOOD_IS_SPECIE DESC,A.NICEFOOD_UPLOAD_TIME DESC");
            }

            strJson = msBsc.AppLogic.Cfg.HttpTools.GetJsonByTable(nds.Tables[0], "", "", 1, 200, "");
            this.ExecJScript(@"var _html = $('#butique_nicefood_list').html();
                            laytpl(_html).render(" + strJson + @", function (render) {
                                $('#butique-nicefood').append(render);
                            })");


            //特产
            DataSet spds;
            using (msBsc.AppLogic.DataAlc.CBizPushSpecialty objCBizPushSpecialty = new AppLogic.DataAlc.CBizPushSpecialty())
            {
                spds = objCBizPushSpecialty.DataObj.QueryBySQL(@"SELECT TOP 3 
            A.SPECIALTY_ID
            ,A.SPECIALTY_NAME
            ,A.SPECIALTY_DEFAULT_PIC 
            FROM DJK_PUSH_SPECIALTY A 
            WHERE LEN(A.SPECIALTY_NAME)<=5 
            ORDER BY A.SPECIALTY_IS_SPECIE DESC,A.SPECIALTY_UPLOAD_TIME DESC");
            }
            strJson = msBsc.AppLogic.Cfg.HttpTools.GetJsonByTable(spds.Tables[0], "", "", 1, 200, "");
            this.ExecJScript(@"var _html = $('#butique_speciety_list').html();
                            laytpl(_html).render(" + strJson + @", function (render) {
                                $('#butique-speciety').append(render);
                            });$(window).resize()");
        }

        public string GetFooterInfo()
        {
            if (string.IsNullOrEmpty(msBsc.SvRef.UserInfo.Operator))
            {
                return "<ul><li class='footer-selected '><img src='/themes/mStyle1/Image/home/bottom-item1.png' /><span>首页</span></li><li><a href='/mp_UserLogin.htm'><img src='/themes/mStyle1/Image/home/index_footer_icon2.png' /><span>登录</span></a></li><li><a href='/mp_UserRegister.htm'><img src='/themes/mStyle1/Image/home/index_footer_icon3.png' /><span>注册</span></a></li></ul>";
            }
            else
            {
                string personalAddr = string.Empty;

                if (msBsc.SvRef.UserInfo.OperType == "1")
                {
                    personalAddr = "/mb_UserInfo.htm";
                }
                else if (msBsc.SvRef.UserInfo.OperType == "2")
                {
                    personalAddr = "/ms_UserInfo.htm";
                }

                return "<ul><li class='footer-selected '><img src='/themes/mStyle1/Image/home/bottom-item1.png' /><span>首页</span></li><li><a href='" + personalAddr + "'><img src='/themes/mStyle1/Image/home/index_footer_icon2.png' /><span>个人中心</span></a></li><li><a href='#' onclick='$.setLoginOut();' id='logout'><img src='/themes/mStyle1/Image/home/index_footer_icon3.png' /><span>退出</span></a></li></ul>";
            }
        }
    }
}